//
//  SetViewController.m
//  YUXiu
//
//  Created by wang on 16/6/29.
//  Copyright © 2016年 Wang. All rights reserved.
//

#import "SetViewController.h"
#import "PasswordViewController.h"

@interface SetViewController (){
    NSArray *firstArr;
    NSArray *secArr;
}

@end

@implementation SetViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"设置";
    firstArr = @[@"消息通知",@"修改密码",@"清除缓存",@"黑名单"];
    secArr = @[@"检查更新",@"用户反馈",@"关于我们"];
    self.tableView.tableFooterView = [self getFootView];
    
}
-(UIView *)getFootView{
    UIView *foot = [[UIView alloc]initWithFrame:krect(0, 0, kScreenWidth, 110)];
    
    UIButton *bottomB =  [[UIButton alloc]initWithFrame:krect(20, 50, kScreenWidth-40, 50)];
    [bottomB setTitle:@"退出登录" forState:UIControlStateNormal];
    [bottomB setTitleColor:kRedCOLOR forState:UIControlStateNormal];
    [bottomB addTarget:self action:@selector(exitLogin) forControlEvents:UIControlEventTouchUpInside];
    bottomB.layer.cornerRadius = 8;
    [bottomB setBackgroundColor:kWhiteCOLOR];
    [foot addSubview:bottomB];
    
    return foot;
}
#pragma mark - tableview
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    if (section == 0) return 4;
    else  return 3;
}
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 2;
}
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return 40;
}
-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    UIView *view = [UIView new];
    return view;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 50;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    static NSString *ide = @"cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:ide];
    if (!cell) {
        cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:ide];
        cell.backgroundColor = kWhiteCOLOR;
        cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
        UIView *line = [[UIView alloc]initWithFrame:krect(8, 49, kScreenWidth-16, 1)];
        line.backgroundColor = kLightGrayCOLOR;
        [cell.contentView addSubview:line];
        
    }
    if (indexPath.section == 0) {
        cell.textLabel.text = firstArr[indexPath.row];
    }else{
        cell.textLabel.text = secArr[indexPath.row];
    }
    
    if (indexPath.section == 0 && indexPath.row==0) {
        //自定义辅助视图为开关控件
        //1.创建一个开关控件的实例
        UISwitch *mySwitch = [[UISwitch alloc]init];
        mySwitch.on = YES;
        //2.将控件实例赋给accessoryView属性
        cell.accessoryView = mySwitch;
        [mySwitch addTarget:self action:@selector(switchAction:) forControlEvents:UIControlEventValueChanged];

    }
  
        return cell;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.section == 0) {
        if (indexPath.row == 1) {
            //修改密码
            PasswordViewController  *passVC = [[PasswordViewController alloc]init];
            [self.navigationController pushViewController:passVC animated:YES];
        }
    }else{
        
    }
    
}
-(void)switchAction:(UISwitch *)sw{
    NSString * str;
    if (sw.on) {
        str = @"消息推送已开启";

    }else{
        str = @"消息推送已关闭";

    }
    [self showHUDWithText:str AfterDelay:1];
}
-(void)exitLogin{
    [self showHUDWithText:@"1s后退出登录" AfterDelay:1];

}





@end
